import 'package:hive_ce/hive.dart';

/// 通用简单存储
class CommonStorage {
  late final Box _box;
  bool _initialized = false;

  Future<CommonStorage> init() async {
    if (!_initialized) {
      _box = await Hive.openBox('app_data');
      _initialized = true;
    }
    return this;
  }

  // 通用存储方法
  Future<void> save(String key, dynamic value) async =>
      await _box.put(key, value);
  dynamic get(String key, {dynamic defaultValue}) =>
      _box.get(key, defaultValue: defaultValue);
  Future<void> remove(String key) async => await _box.delete(key);
}
